package com.example.christina.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import com.example.christina.enity.Orders;
import com.example.christina.service.OrdersService;

@RestController
@RequestMapping(value = "order")
public class OrderController {

    @Autowired
    private OrdersService ordersService;
    //发货，即已卖出
    @PostMapping(path = "addOrder")
    public void add (@RequestBody Orders orders)
    {
        ordersService.addOrders(orders);
    }

    @DeleteMapping(path = "deleteOrder")
    public void delete(@RequestBody Orders orders)
    {
        ordersService.deleteOrders(orders);
    }

    @GetMapping(path = "solded")
    public String  solded(@RequestParam(required = true) Integer id)
    {
        ordersService.updateOrders(id);
        return ordersService.findOrderById(id).getIfSold();
    }

    @GetMapping(path = "back")
    public String back(@RequestParam(required = true) Integer id)
    {
        ordersService.updateOrders(id);
        return ordersService.findOrderById(id).getIfSold();
    }

    @GetMapping(path = "know")
    public String know(@RequestParam(required = false) Integer id)
    {
        return ordersService.findOrderById(id).getIfSold();
    }

    @GetMapping(path = "findId")
    public List<?> findId(@RequestParam(required = true)Integer id)
    {
        List<Orders> res = new ArrayList<>();
        res.add(ordersService.findOrderById(id));
        return res;
    }

    @GetMapping(path = "findName")
    public List<List<?>> findName(@RequestParam(required = true)String name)
    {
        List<List<?>> res = new ArrayList<>();
        res.add(ordersService.findOrderByUserName(name));
        return res;
    }

    @GetMapping(path = "print")
    public List<List<?>> printAll()
    {
        List<List<?>> res = new ArrayList<>();
        res.add(ordersService.findAll());
        return res;
    }
}
